package ${package}.${subPackageName};

import javax.persistence.GenerationType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Column;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotBlank;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Lists;
import com.google.common.collect.ImmutableList;
import java.util.Date;
import java.util.List;
import java.io.Serializable;

/**
 * @author ${author}
 *
 */
@Entity
@Table(name = "${tableName}")
public class ${className} implements Serializable{
		
		<#if fieldList?exists>
			<#list fieldList as field>
				<#if field.display=="Y">
				
		/**
		 * ${field.columnLabel}
		 */
		private ${field.javaColumnTypeName} ${field.javaColumnAttrName};
				</#if>
			</#list>
		</#if>
		
		<#if fkList?exists>
			<#list fkList as fk>
		/**
		 * ${fk.pkJavaClassName}
		 */
		private ${fk.pkJavaClassName} ${fk.pkJavaClassAttrName};
			</#list>
		</#if>
		
		<#if refList?exists>
			<#list refList as ref>
				<#if ref.refTypeName=="one2many">

		private List<${ref.className}> ${ref.classAttrName}List;				
				</#if>

				<#if ref.refTypeName=="many2many">
		private List<${ref.refClassName}> ${ref.refClassAttrName}M2MList;				
				</#if>
			</#list>
		</#if>
		
		<#if fieldList?exists>
			<#list fieldList as field>
				<#if field.display=="Y">
				
					<#if pkList?exists>
						<#list pkList as pk>
							<#if pk.columnName==field.columnName>
		@Id
		<#if field.isAutoIncrement?exists&&field.isAutoIncrement==true>
		@GeneratedValue(strategy = GenerationType.IDENTITY)
		</#if>
		@Column(name="${field.columnName}")
							</#if>
						</#list>
					</#if>
					<#if field.javaColumnTypeName=="Date">
		@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
		@Temporal(TemporalType.TIMESTAMP)
					<#else>
				<#if field.isNullable==0>
		@NotBlank
				</#if>
					</#if>
		public ${field.javaColumnTypeName} get${field.javaColumnName}(){
			return this.${field.javaColumnAttrName};
		}
		
		public void set${field.javaColumnName}(${field.javaColumnTypeName} ${field.javaColumnAttrName}){
			this.${field.javaColumnAttrName} = ${field.javaColumnAttrName};
		}
		
				</#if>
			</#list>
		</#if>
		
		<#if refList?exists>
			<#list refList as ref>
			<#if ref?exists>
				<#if ref.refTypeName=="one2many">
				
		@OneToMany(mappedBy = "${classAttrName}")
		public List<${ref.className}> get${ref.className}List(){
			return this.${ref.classAttrName}List;
		}
		
		public void set${ref.className}List(List<${ref.className}> ${ref.classAttrName}List){
			this.${ref.classAttrName}List = ${ref.classAttrName}List;
		}
				</#if>
				<#if ref.refTypeName=="many2many">
				
		@ManyToMany
		@JoinTable(name = "${ref.refTableName}", joinColumns={@JoinColumn(name="${ref.columnName}") },inverseJoinColumns={@JoinColumn(name="${ref.refColumnName}")})		
		public List<${ref.refClassName}> get${ref.refClassName}M2MList(){
			return this.${ref.refClassAttrName}M2MList;
		}
		
		public void set${ref.refClassName}M2MList(List<${ref.refClassName}> ${ref.refClassAttrName}M2MList){
			this.${ref.refClassAttrName}M2MList = ${ref.refClassAttrName}M2MList;
		}
				</#if>
				</#if>
			</#list>
		</#if>		
		<#if fkList?exists>
			<#list fkList as fk>
					<#if fk.pkTableName==fk.pkTableName && fk.pkColumnName!=fk.fkColumnName >

		@OneToOne
		@JoinColumn(name = "${fk.fkColumnName}")					
					<#else>
					
		@ManyToOne
		@JoinColumn(name = "${fk.pkColumnName}")
					</#if> 
		public ${fk.pkJavaClassName} get${fk.pkJavaClassName}(){
			return this.${fk.pkJavaClassAttrName};
		}
		
		public void set${fk.pkJavaClassName}(${fk.pkJavaClassName} ${fk.pkJavaClassAttrName}){
			this.${fk.pkJavaClassAttrName} = ${fk.pkJavaClassAttrName};
		}
			</#list>
		</#if>

		
		@Override
		public String toString() {
			return ToStringBuilder.reflectionToString(this);
		}
	
	}

